<template>
  <div class="msg-item">
    <div v-if="information.user_type === 'admin'" class="client">
      <img
        style="margin-right: 14px"
        class="avatar"
        :src="information.head_img"
        alt=""
      />
      <div class="bubble">
        <pre
          v-if="information.type === 'text'"
          v-html="information.content"
        ></pre>
        <div v-if="information.type === 'image'">
          <el-image
            style="
              height: 150px;
              cursor: pointer;
              border-radius: 4px;
              max-width: 100%;
            "
            :src="information.content"
            :preview-src-list="[information.content]"
            :fit="'contain'"
            :preview-teleported="true"
          />
        </div>
        <div v-if="information.type === 'audio'">
          <video style="max-height: 200px; max-width: 200px">
            <source :src="information.content" />
          </video>
        </div>
        <!-- <span>{{ information.msg_is_read ? '已读' : '未读' }}</span> -->
      </div>
    </div>

    <!--  访客  -->
    <div v-if="information.user_type == 'member'" class="merchant">
      <img
        style="margin-left: 14px"
        class="avatar"
        :src="information.head_img"
        alt=""
      />
      <div class="bubbleSel">
        <pre
          v-if="information.type === 'text'"
          v-html="information.content"
        ></pre>
        <div v-if="information.type === 'image'">
          <el-image
            style="
              height: 150px;
              cursor: pointer;
              border-radius: 4px;
              max-width: 100%;
            "
            :src="information.content"
            :preview-src-list="[information.content]"
            :preview-teleported="true"
          />
        </div>
        <div v-if="information.type === 'audio'">
          <video style="max-height: 200px; max-width: 200px" autoplay controls>
            <source :src="information.content" />
          </video>
        </div>
        <!-- <span>{{ information.msg_is_read ? '已读' : '未读' }}</span> -->
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from "vue";
import { type ChatHistory } from "@/utils/socket";
const props = defineProps({
  information: {
    type: Object as () => ChatHistory,
    default: () => {},
  },
});
</script>
<style>
.msg-item {
  width: 96%;
  margin: 0 auto;
}
.client {
  display: -webkit-flex;
  /* Safari */
  display: flex;
  width: 100%;
  margin: 20px 0;
  flex-wrap: wrap;
  align-items: flex-start;
}

.merchant {
  display: -webkit-flex;
  /* Safari */
  display: flex;
  width: 100%;
  margin: 20px 0;
  flex-wrap: wrap;
  align-items: flex-start;
  flex-direction: row-reverse;
}
.bubble,
.bubbleSel {
  padding: 10px;
  position: relative;
  background: #fff;
  border-radius: 6px;
  max-width: calc(100% - 110px);
  min-height: 41px;
}

.close {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 999;
  color: #f2f2f2;
  height: 40px;
  background: #00000066;
  width: 100%;
  display: flex;
  justify-content: flex-end;
  padding-right: 10px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 20px;
}

pre {
  overflow: auto;
  padding: 0;
  margin: 0;
  font-size: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-family: system-ui;
}
</style>
